<template>
    <!-- 添加或修改采购订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="备注" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入备注"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="删除标志" prop="delFlag">
                                <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                                <el-input v-model="form.purchaserHqCode" placeholder="请输入采购方总部编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商编码" prop="supplierCode">
                                <el-input v-model="form.supplierCode" placeholder="请输入供应商编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商名称" prop="supplierName">
                                <el-input v-model="form.supplierName" placeholder="请输入供应商名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产订单号" prop="sellerSignStartTime">
                                <el-input v-model="form.sellerSignStartTime" placeholder="请输入生产订单号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同签订开始日期" prop="sellerSignEndTime">
                                <el-input v-model="form.sellerSignEndTime" placeholder="请输入合同签订开始日期"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同签订结束日期" prop="modifyStartTime">
                                <el-input v-model="form.modifyStartTime" placeholder="请输入合同签订结束日期"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="更新时间起" prop="modifyEndTime">
                                <el-input v-model="form.modifyEndTime" placeholder="请输入更新时间起"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="更新时间止" prop="conValidStartTime">
                                <el-input v-model="form.conValidStartTime" placeholder="请输入更新时间止"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同生效开始日期" prop="conValidEndTime">
                                <el-input v-model="form.conValidEndTime" placeholder="请输入合同生效开始日期"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同生效结束日期" prop="sellerConCode">
                                <el-input v-model="form.sellerConCode" placeholder="请输入合同生效结束日期"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同编号" prop="conCode">
                                <el-input v-model="form.conCode" placeholder="请输入合同编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同编号" prop="poNo">
                                <el-input v-model="form.poNo" placeholder="请输入合同编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="每页条数" prop="pageSize">
                                <el-input v-model="form.pageSize" placeholder="请输入每页条数"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="当前页码" prop="pageNum">
                                <el-input v-model="form.pageNum" placeholder="请输入当前页码"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "FactoryPurchaseMainForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/factoryPurchaseMain/factoryPurchaseMain/',
                    add:'/factoryPurchaseMain/factoryPurchaseMain/add',
                    edit:'/factoryPurchaseMain/factoryPurchaseMain/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
        status: "0",
            remark: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            delFlag: null,
            purchaserHqCode: null,
            supplierCode: null,
            supplierName: null,
            sellerSignStartTime: null,
            sellerSignEndTime: null,
            modifyStartTime: null,
            modifyEndTime: null,
            conValidStartTime: null,
            conValidEndTime: null,
            sellerConCode: null,
            conCode: null,
            poNo: null,
            pageSize: null,
            pageNum: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加采购订单信息";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改采购订单信息";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
